package com.lxr.activity;

import java.util.ArrayList;

import com.wxq.schoolmap.R;
import android.content.Context;  
import android.graphics.Color;  
import android.view.LayoutInflater;  
import android.view.View;  
import android.view.ViewGroup;  
import android.widget.BaseAdapter;  
import android.widget.LinearLayout;  
import android.widget.TextView;  
  
public class ListviewAdapter extends BaseAdapter{  
      
    private LayoutInflater inflater = null;  
    private ArrayList<String> items = null;  
          
    private int selectedPosition = 0;    
    public void setSelectedPosition(int position) {  
        selectedPosition = position;  
    }  
            
    public ListviewAdapter(Context context, ArrayList<String> arraylist) {  
        // TODO Auto-generated constructor stub   
        // LayoutInflater�������ؽ���   
        inflater = LayoutInflater.from(context);  
        // �����������е�ÿ���������Ϣ   
        this.items = arraylist;  
        // �����Դ�е�ͼƬ��ΪҪ��ʾ��ͼ��   
    }    
          
    @Override  
    public int getCount() {  
        // TODO Auto-generated method stub   
        return items.size();  
    }    
          
    @Override  
    public Object getItem(int position) {  
        // TODO Auto-generated method stub   
        return items.get(position);  
    }  
          
    @Override  
    public long getItemId(int position) {  
        // TODO Auto-generated method stub   
        return position;  
    }  
      
    // ����ÿ���еĿؼ�������   
    class ViewHolder {  
        TextView text;  
        LinearLayout layout;  
    }  
          
    @Override    
    public View getView(int position, View convert, ViewGroup parent) {  
       // TODO Auto-generated method stub   
       ViewHolder holder;  
       if(convert == null)  
       {  
            // ����LayoutInflater��inflate��������layout�ļ����еĽ���   
            convert = inflater.inflate(R.layout.list_row, null);  
            holder = new ViewHolder();  
            holder.text = (TextView)convert.findViewById(R.id.text);   
            holder.layout = (LinearLayout)convert.findViewById(R.id.layout);  
            // �����ǰ��ؼ��Ķ���   
            convert.setTag(holder);  
        } else {  
            // ��ȡ��ǰ��ؼ��Ķ���   
            holder = (ViewHolder)convert.getTag();  
        }  
        // ���õ�ǰ�������   
        holder.text.setText(items.get(position));  
        // ����ѡ��Ч��   
           if(selectedPosition == position)  
            {  
            holder.text.setTextColor(Color.BLUE);  
            holder.layout.setBackgroundResource(R.drawable.glass2);  
            } else {  
            holder.text.setTextColor(Color.WHITE);  
            holder.layout.setBackgroundResource(R.drawable.glass);  
            }  
        return convert;  
    }  
}  